Generating tileable terrain using Perlin Noise [duplicate]

Posted by terrorcell on Game Development See other posts from Game Development or by terrorcell
Published on 2013-10-08T14:01:22Z Indexed on 2014/08/19 16:32 UTC
Read the original article Hit count: 265

Filed under:
|
|

This question already has an answer here:

I'm having trouble figuring out the solution to this particular algorithm. I'm using the Perlin Noise implementation from: https://code.google.com/p/mikeralib/source/browse/trunk/Mikera/src/main/java/mikera/math/PerlinNoise.java

Here's what I have so far:

for (Chunk chunk : chunks)
    {
        PerlinNoise noise = new PerlinNoise();
        for (int y = 0; y < CHUNK_SIZE_HEIGHT; ++y)
        {
            for (int x = 0; x < CHUNK_SIZE_WIDTH; ++x)
            {
                int index = get1DIndex(y, CHUNK_SIZE_WIDTH, x);

                float val = 0;
                for (int i = 2; i <= 32; i *= i)
                {
                    double n = noise.tileableNoise2(i * x / (float)CHUNK_SIZE_WIDTH, i * y / (float)CHUNK_SIZE_HEIGHT, CHUNK_SIZE_WIDTH, CHUNK_SIZE_HEIGHT);                        
                    val += n / i;
                }

                // chunk tile at [index] gets set to the colour 'val'
            }
        }
    }

Which produces something like this: enter image description here

Each chunk is made up of CHUNK_SIZE number of tiles, and each tile has a TILE_SIZE_WIDTH/HEIGHT. I think it has something to do with the inner-most for loop and the x/y co-ords given to the noise function, but I could be wrong.

Solved:

PerlinNoise noise = new PerlinNoise();
for (Chunk chunk : chunks)
    {
        for (int y = 0; y < CHUNK_SIZE_HEIGHT; ++y)
        {
            for (int x = 0; x < CHUNK_SIZE_WIDTH; ++x)
            {
                int index = get1DIndex(y, CHUNK_SIZE_WIDTH, x);

                float val = 0;
                float xx = x * TILE_SIZE_WIDTH + chunk.x;
                float yy = y * TILE_SIZE_HEIGHT + chunk.h;
                int w = CHUNK_SIZE_WIDTH * TILE_SIZE_WIDTH;
                int h = CHUNK_SIZE_HEIGHT * TILE_SIZE_HEIGHT;
                for (int i = 2; i <= 32; i *= i)
                {
                    double n = noise.tileableNoise2(i * xx / (float)w, i * yy / (float)h, w, h);                        
                    val += n / i;
                }

                // chunk tile at [index] gets set to the colour 'val'
            }
        }
    }

© Game Development or respective owner

Related posts about java

Related posts about tiles